import { useSnackbar } from 'notistack';

// generalOptions 初始化配置
const snackbar = (generalOptions = {}) => {
  const { enqueueSnackbar, closeSnackbar } = useSnackbar();
  // 默认配置
  const defaultOptions = {
    // variant: 'default', // default | error | success | warning | info
    autoHideDuration: 3000,
    disableWindowBlurListener: true,
    preventDuplicate: true,
  };

  return {
    // options 调用配置
    enqueueSnackbar: (message, options = {}) => {
      enqueueSnackbar(message, {
        ...defaultOptions,
        ...generalOptions,
        ...options,
      });
    },
    closeSnackbar,
  };
};

export default snackbar;
